package com.ruoyi.web.controller.counter;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.counter.domain.Workorder;
import com.ruoyi.counter.service.IWorkorderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工单信息Controller
 *
 * @author xll
 * @date 2021-08-02
 */
@RestController
@RequestMapping("/counter/workorder")
public class WorkorderController extends BaseController
{
    @Autowired
    private IWorkorderService workorderService;

    /**
     * 查询工单信息列表
     */
    @PreAuthorize("@ss.hasPermi('counter:workorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(Workorder workorder)
    {
        startPage();
        List<Workorder> list = workorderService.selectWorkorderList(workorder);
        return getDataTable(list);
    }

    /**
     * 导出工单信息列表
     */
    @PreAuthorize("@ss.hasPermi('counter:workorder:export')")
    @Log(title = "工单信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Workorder workorder)
    {
        List<Workorder> list = workorderService.selectWorkorderList(workorder);
        ExcelUtil<Workorder> util = new ExcelUtil<Workorder>(Workorder.class);
        return util.exportExcel(list, "工单信息数据");
    }

    /**
     * 获取工单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('counter:workorder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(workorderService.selectWorkorderById(id));
    }

    /**
     * 新增工单信息
     */
    @PreAuthorize("@ss.hasPermi('counter:workorder:add')")
    @Log(title = "工单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Workorder workorder)
    {
        return toAjax(workorderService.insertWorkorder(workorder));
    }

    /**
     * 修改工单信息
     */
    @PreAuthorize("@ss.hasPermi('counter:workorder:edit')")
    @Log(title = "工单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Workorder workorder)
    {
        return toAjax(workorderService.updateWorkorder(workorder));
    }

    /**
     * 删除工单信息
     */
    @PreAuthorize("@ss.hasPermi('counter:workorder:remove')")
    @Log(title = "工单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workorderService.deleteWorkorderByIds(ids));
    }
}
